//package com.frank.threadPoolSave.web;
//
//import com.frank.threadPoolSave.service.MyAsyncService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.concurrent.MyCountDownLatch;
//
///**
// * @author 小石潭记
// * @date 2020/11/22 11:26
// * @Description: ${todo}
// */
//@RestController
//@RequestMapping("/thread/pool/save")
//public class ThreadPoolAsyncSaveController {
//
//    /* 调用await()方法的线程会被挂起，它会等待直到count值为0才继续执行
//    public void await() throws InterruptedException { };
//
//    和await()类似，只不过等待一定的时间后count值还没变为0的话就会继续执行
//    public boolean await(long timeout, TimeUnit unit) throws InterruptedException { };
//
//    将count值减1
//    public void countDown() { };*/
//
//    private MyCountDownLatch countDownLatch;
//
//    @Autowired
//    private MyAsyncService myAsyncService;
//
//    @GetMapping
//    public void save() {
//        // 二十万条数据 每页查询10000条
//        int total = 5000, pageSize = 10;
//        int num = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
//        try {
//            countDownLatch = new MyCountDownLatch(num);
//            //计数器数量就等于文件数量,因为每个文件会开一个线程
//            for (int i = 0; i < num; i++) {
//                myAsyncService.dataBaseToQueue(countDownLatch, i);
//            }
//            countDownLatch.await();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//    }
//
//}
